package com.cndcare.msc.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StartPcUtil {
    public static void main(String[] args) throws Exception {
        System.out.println(StartPcUtil.readSystemStartTime());
    }

    public static Date readSystemStartTime() throws Exception {
        Process process = Runtime.getRuntime().exec("cmd /c net statistics workstation");
        String startUpTime = "";
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
        int i = 0;
        String timeWith;
        while ((timeWith = bufferedReader.readLine()) != null) {
            if (i == 3) {
                startUpTime = timeWith.substring(8);
            }
            i++;
        }
        process.waitFor();
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return df.parse(startUpTime);
    }
}